//package work.mediway.mdm.controller.biz;
//
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
//import com.github.xiaoymin.knife4j.annotations.ApiSupport;
//import com.mediway.common.annotation.Log;
//import com.mediway.common.core.redis.RedisCache;
//import com.mediway.common.enums.BusinessType;
//import com.mediway.common.utils.spring.SpringUtils;
//import com.mediway.hos.base.model.BaseResponse;
//
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.Comparator;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
//import javax.validation.Valid;
//import javax.validation.constraints.NotBlank;
//
//import cn.hutool.core.util.ObjectUtil;
//import cn.hutool.core.util.PageUtil;
//import cn.hutool.core.util.StrUtil;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import work.mediway.mdm.core.annotation.OpsLog;
//import work.mediway.mdm.core.constant.MdmConstant;
//import work.mediway.mdm.core.enums.OpsLogTypeEnum;
//import work.mediway.mdm.core.page.QueryRequest;
//import work.mediway.mdm.core.transport.ErrorMsgVO;
//import work.mediway.mdm.core.vo.TableVO;
//import work.mediway.mdm.biz.dto.biz.DataQualityConfigDTO;
//import work.mediway.mdm.biz.dto.biz.DataQualityDataExceptionDealDTO;
//import work.mediway.mdm.biz.dto.biz.DataQualityJobDTO;
//import work.mediway.mdm.biz.dto.biz.DataQualityListDTO;
//import work.mediway.mdm.biz.dto.biz.DataQualityVerifyDTO;
//import work.mediway.mdm.biz.entity.biz.SsDataQualityConfig;
//import work.mediway.mdm.biz.entity.biz.SsDataQualityLog;
//import work.mediway.mdm.biz.entity.biz.SsDataQualityLogItem;
//import work.mediway.mdm.biz.service.biz.SsDataQualityConfigService;
//import work.mediway.mdm.biz.service.biz.SsDataQualityLogItemService;
//import work.mediway.mdm.biz.service.biz.SsDataQualityLogService;
//import work.mediway.mdm.biz.vo.biz.SsDataQualityLogVO;
//import work.mediway.mdm.biz.vo.biz.SsDataQualityTableVO;
//import work.mediway.mdm.biz.vo.dict.DictFieldVO;
//
///**
// * 数据质量管理模块
// *
// * @author zhongyj <1126834403@qq.com><br/>
// * @date 2022/7/11
// */
// TODO: 2022/10/6
//@Api(tags = "数据质量管理模块")
//@ApiSupport(order = 26)
//@RestController
//@Validated
//@Slf4j
//@RequestMapping("data/quality")
//@RequiredArgsConstructor
//public class DataQualityController {
//
//    private final SsDataQualityConfigService dataQualityConfigService;
//    private final SsDataQualityLogService dataQualityLogService;
//    private final SsDataQualityLogItemService dataQualityLogItemService;
//
//    @Log(title = "新增数据质量配置信息", businessType = BusinessType.INSERT)
//    @OpsLog(value = "新增数据质量配置信息", type = OpsLogTypeEnum.INSERT)
//    @ApiOperation(value = "新增数据质量配置信息")
//    @ApiOperationSupport(order = 1)
//    @PostMapping("config")
//    public BaseResponse<ErrorMsgVO> insertDataQualityConfig(@RequestBody @Valid DataQualityConfigDTO dataQualityConfigDTO) {
//        ErrorMsgVO errorMsgVO = this.dataQualityConfigService.insertDataQualityConfig(dataQualityConfigDTO);
//        return BaseResponse.success(errorMsgVO);
//    }
//
//    @Log(title = "删除数据质量配置信息", businessType = BusinessType.DELETE)
//    @OpsLog(value = "删除数据质量配置信息", type = OpsLogTypeEnum.DELETE)
//    @ApiOperation(value = "删除数据质量配置信息")
//    @ApiOperationSupport(order = 2)
//    @PostMapping("config/remove")
//    public BaseResponse<String> removeDataQualityConfig(@RequestBody List<String> configIds) {
//        this.dataQualityConfigService.removeDataQualityConfig(configIds);
//        return BaseResponse.success();
//    }
//
//    @OpsLog(value = "查询数据质量配置信息", type = OpsLogTypeEnum.SELECT)
//    @ApiOperation(value = "查询数据质量配置信息")
//    @ApiOperationSupport(order = 3)
//    @GetMapping("config")
//    public BaseResponse<List<SsDataQualityConfig>> selectDataQualityConfig(SsDataQualityConfig dataQualityConfig) {
//        List<SsDataQualityConfig> dataQualityConfigs = this.dataQualityConfigService.selectDataQualityConfig(dataQualityConfig);
//        return BaseResponse.success(dataQualityConfigs);
//    }
//
//    @OpsLog(value = "查询系统schema", type = OpsLogTypeEnum.SELECT)
//    @ApiOperation(value = "查询系统schema")
//    @ApiOperationSupport(order = 4)
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "接入系统id", name = "accessSystemId", paramType = "query", required = true)
//    })
//    @GetMapping("system/schema")
//    public BaseResponse<List<Map<String, String>>> selectSourceSystemSchema(@NotBlank(message = "不能为空") String accessSystemId) {
//        List<Map<String, String>> sourceSystemSchema = this.dataQualityConfigService.selectSourceSystemSchema(accessSystemId);
//        return BaseResponse.success(sourceSystemSchema);
//    }
//
//    @OpsLog(value = "查询系统表信息", type = OpsLogTypeEnum.SELECT)
//    @ApiOperation(value = "查询系统表信息")
//    @ApiOperationSupport(order = 4)
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "接入系统id", name = "accessSystemId", paramType = "query", required = true),
//            @ApiImplicitParam(value = "系统Schema(可以为空)", name = "sourceSchema", paramType = "query"),
//            @ApiImplicitParam(value = "表名或者表描述", name = "param", paramType = "query")
//    })
//    @GetMapping("system/table")
//    public BaseResponse<Page<TableVO>> selectSourceSystemTable(@NotBlank(message = "不能为空") String accessSystemId, String sourceSchema, String param, QueryRequest queryRequest) {
//        List<TableVO> sourceSystemSchema = this.dataQualityConfigService.selectSourceSystemTable(accessSystemId, sourceSchema);
//        PageUtil.setOneAsFirstPageNo();
//        List<TableVO> sort = sourceSystemSchema.stream().sorted(Comparator.comparing(TableVO::getTableCode)).collect(Collectors.toList());
//        List<TableVO> filter = StrUtil.isNotBlank(param)
//                ? sort.stream().filter(item -> StrUtil.containsIgnoreCase(item.getTableCode(), param) || StrUtil.contains(item.getTableName(), param)).collect(Collectors.toList())
//                : sort;
//        List<TableVO> result = filter.stream()
//                .skip(PageUtil.getStart(queryRequest.getCurrent(), queryRequest.getSize()))
//                .limit(queryRequest.getSize()).collect(Collectors.toList());
//        Page<TableVO> page = new Page<>(queryRequest.getCurrent(), queryRequest.getSize());
//        page.setRecords(result);
//        page.setTotal(filter.size());
//        page.setCurrent(queryRequest.getSize());
//        page.setPages(PageUtil.totalPage(filter.size(), queryRequest.getSize()));
//        return BaseResponse.success(page);
//    }
//
//    @OpsLog(value = "查询系统字典列名", type = OpsLogTypeEnum.SELECT)
//    @ApiOperation(value = "查询系统字典列名")
//    @ApiOperationSupport(order = 5)
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "接入系统id", name = "accessSystemId", paramType = "query", required = true),
//            @ApiImplicitParam(value = "系统Schema(可以为空)", name = "sourceSchema", paramType = "query"),
//            @ApiImplicitParam(value = "系统表名称", name = "tableCode", paramType = "query", required = true)
//    })
//    @GetMapping("system/column")
//    public BaseResponse<List<DictFieldVO>> selectSourceSystemColumn(@NotBlank(message = "不能为空") String accessSystemId, String sourceSchema, @NotBlank(message = "不能为空") String tableCode) {
//        List<DictFieldVO> sourceSystemColumn = this.dataQualityConfigService.selectSourceSystemColumn(accessSystemId, sourceSchema, tableCode);
//        return BaseResponse.success(sourceSystemColumn);
//    }
//
//    @Log(title = "开启数据质量校验", businessType = BusinessType.OTHER)
//    @OpsLog(value = "开启数据质量校验", type = OpsLogTypeEnum.INSERT)
//    @ApiOperation(value = "开启数据质量校验")
//    @ApiOperationSupport(order = 7)
//    @PostMapping("verify")
//    public BaseResponse<List<SsDataQualityLogVO>> startDataQuality(@Valid @RequestBody List<DataQualityVerifyDTO> dataQualityVerifyDTO) {
//        List<SsDataQualityLogVO> dataQualityLog = this.dataQualityConfigService.startDataQuality(dataQualityVerifyDTO);
//        return BaseResponse.success(dataQualityLog);
//    }
//
//    @OpsLog(value = "查询数据质量表列表", type = OpsLogTypeEnum.SELECT)
//    @ApiOperation(value = "查询数据质量表列表")
//    @ApiOperationSupport(order = 9)
//    @GetMapping("table")
//    public BaseResponse<Page<SsDataQualityTableVO>> getDataQualityTable(DataQualityListDTO dataQualityListDTO, QueryRequest queryRequest) {
//        Page<SsDataQualityTableVO> page = new Page<>(queryRequest.getCurrent(), queryRequest.getSize());
//        page.setRecords(this.dataQualityConfigService.getDataQualityTable(dataQualityListDTO));
//        return BaseResponse.success(page);
//    }
//
//    @OpsLog(value = "查询数据质量结果", type = OpsLogTypeEnum.SELECT)
//    @ApiOperation(value = "查询数据质量结果")
//    @ApiOperationSupport(order = 11)
//    @GetMapping("log")
//    public BaseResponse<Page<SsDataQualityLog>> selectDataQualityLog(SsDataQualityLog dataQualityLog, QueryRequest queryRequest) {
//        Page<SsDataQualityLog> page = new Page<>(queryRequest.getCurrent(), queryRequest.getSize());
//        page.setRecords(this.dataQualityLogService.selectDataQualityLog(dataQualityLog));
//        return BaseResponse.success(page);
//    }
//
//    @OpsLog(value = "查询数据质量结果详情", type = OpsLogTypeEnum.SELECT)
//    @ApiOperation(value = "查询数据质量结果详情")
//    @ApiOperationSupport(order = 12)
//    @GetMapping("log/item")
//    public BaseResponse<Page<SsDataQualityLogItem>> selectDataQualityLogItem(SsDataQualityLogItem dataQualityLogItem, QueryRequest queryRequest) {
//        Page<SsDataQualityLogItem> page = new Page<>(queryRequest.getCurrent(), queryRequest.getSize());
//        page.setRecords(this.dataQualityLogItemService.selectDataQualityLogItem(dataQualityLogItem));
//        return BaseResponse.success(page);
//    }
//
//    // TODO: 2022/10/6
//    /*@Log(title = "新增数据质量任务", businessType = BusinessType.INSERT)
//    @OpsLog(value = "新增数据质量任务", type = OpsLogTypeEnum.INSERT)
//    @ApiOperation(value = "新增数据质量任务")
//    @ApiOperationSupport(order = 13)
//    @PostMapping("job")
//    public BaseResponse<String> addDataQualityJob(@RequestBody SysJob job) {
//        if (!CronUtils.isValid(job.getCronExpression())) {
//            return BaseResponse.failed("新增任务'" + job.getJobName() + "'失败，Cron表达式不正确");
//        } else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), "rmi:")) {
//            return BaseResponse.failed("新增任务'" + job.getJobName() + "'失败，目标字符串不允许'rmi'调用");
//        } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{"ldap:", "ldaps:"})) {
//            return BaseResponse.failed("新增任务'" + job.getJobName() + "'失败，目标字符串不允许'ldap'调用");
//        } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[]{"http://", "https://"})) {
//            return BaseResponse.failed("新增任务'" + job.getJobName() + "'失败，目标字符串不允许'http(s)'调用");
//        } else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR)) {
//            return BaseResponse.failed("新增任务'" + job.getJobName() + "'失败，目标字符串存在违规");
//        } else {
//            this.dataQualityConfigService.addDataQualityJob(job);
//        }
//        return BaseResponse.success();
//    }*/
//
//    @Log(title = "数据质量绑定任务", businessType = BusinessType.INSERT)
//    @OpsLog(value = "数据质量绑定任务", type = OpsLogTypeEnum.INSERT)
//    @ApiOperation(value = "数据质量绑定任务")
//    @ApiOperationSupport(order = 15)
//    @PostMapping("bind/job")
//    public BaseResponse<String> dataQualityBindJob(@RequestBody @Valid DataQualityJobDTO dataQualityJob) {
//        this.dataQualityConfigService.dataQualityBindJob(dataQualityJob);
//        return BaseResponse.success();
//    }
//
//    @Log(title = "处理异常值", businessType = BusinessType.UPDATE)
//    @OpsLog(value = "处理异常值", type = OpsLogTypeEnum.UPDATE)
//    @ApiOperation(value = "处理异常值")
//    @ApiOperationSupport(order = 17)
//    @PostMapping("exception")
//    public BaseResponse<ErrorMsgVO> dataQualityDataExceptionDeal(@RequestBody List<DataQualityDataExceptionDealDTO> dataExceptionDeals) {
//        ErrorMsgVO msgVO = this.dataQualityLogItemService.dataQualityDataExceptionDeal(dataExceptionDeals);
//        return BaseResponse.success(msgVO);
//    }
//
//    @Log(title = "手动比对", businessType = BusinessType.UPDATE)
//    @OpsLog(value = "手动比对", type = OpsLogTypeEnum.UPDATE)
//    @ApiOperation(value = "手动比对")
//    @ApiOperationSupport(order = 19)
//    @PostMapping("opera")
//    public BaseResponse<ErrorMsgVO> dataQualityDataExceptionOperaDeal(@RequestBody List<String> logItemIds) {
//        ErrorMsgVO msgVO = this.dataQualityLogItemService.dataQualityDataExceptionOperaDeal(logItemIds);
//        return BaseResponse.success(msgVO);
//    }
//
//    @ApiOperation(value = "获取任务进度")
//    @ApiOperationSupport(order = 21)
//    @PostMapping("plan/{logId}")
//    public BaseResponse<Object> dataQualityPlan(@PathVariable String logId) {
//        Object value = SpringUtils.getBean(RedisCache.class).getCacheObject(StrUtil.format(MdmConstant.RedisConst.DATA_QUALITY_PLAN, logId));
//        Object msg = SpringUtils.getBean(RedisCache.class).getCacheObject(StrUtil.format(MdmConstant.RedisConst.DATA_QUALITY_PLAN, logId + "-msg"));
//        return BaseResponse.success(ObjectUtil.isNotEmpty(msg) ? StrUtil.toString(msg) : "", value);
//    }
//
//}
